.panel.panel-default
  .panel-heading
    .row
      .col-sm-6
        h5
          ' Registered users
      .col-sm-6.text-right
        = link_to new_admin_user_path, class: 'btn btn-xs btn-link', role: 'button'
          i.fa.fa-plus-circle
          | Create new user
  .panel-body
    .table-responsive
      table.table.table-stripped.table-hover
        col.col-20
        col.col-30
        col.col-10
        col.col-10
        col.col-10
        col.col-10
        col.col-10
        thead
          tr
            th Name
            th Email
            th Admin
            th Namespaces
            th Teams
            th Enabled
            th Remove
        tbody
          - @users.each do |user|
            tr[id="user_#{user.id}"]
              - if user == current_user
                td= user.display_username
              - else
                td
                  = link_to user.display_username, edit_admin_user_path(user), { title: "Edit user '#{user.display_username}'" }
              td= user.email
              td.admin-btn
                - if current_user.id == user.id
                  i.fa.fa-lg[class="fa-toggle-#{user.admin? ? 'on': 'off'}"]
                - else
                  a[class="btn btn-default"
                    data-remote="true"
                    data-method="put"
                    rel="nofollow"
                    href=url_for(toggle_admin_admin_user_path(user))]
                      i.fa.fa-lg[class="fa-toggle-#{user.admin? ? 'on': 'off'}"]

              td= user.teams.reduce(0) { |sum, t| sum += t.namespaces.count}
              td= user.teams.all_non_special.count
              td.enabled-btn
                - if current_user.id == user.id && @admin_count == 1
                  i.fa.fa-lg.fa-toggle-on
                - else
                  a[class="btn btn-default"
                    data-remote="true"
                    data-method="put"
                    rel="nofollow"
                    href=url_for(toggle_enabled_path(user))]
                      i.fa.fa-lg[class="fa-toggle-#{user.enabled? ? 'on': 'off'}"]
              td.remove-btn
                - if current_user == user
                    a[class="btn btn-default" disabled=true]
                      i.fa.fa-trash.fa-lg
                - else
                    a[class="btn btn-default"
                        data-placement="left"
                        data-toggle="popover"
                        data-title="Please confirm"
                        data-content='<p>Are you sure you want to remove this user?</p><a class="btn btn-default">No</a> <a class="btn btn-primary btn-confirm-remove" data-method="delete" rel="nofollow" href="#{admin_user_path(user)}">Yes</a>'
                        data-html="true"
                        tabindex="0"
                        role="button"
                    ]
                      i.fa.fa-trash.fa-lg
  .panel-footer= paginate(@users)
